<?php
namespace Apps\AppApi\Method\BeautyParlor;

use Apps\AppApi\Method\BaseMethod;
use Apps\Common\Libs\PicUrl;
use Apps\Common\Models\BeautyParlorService;
use Apps\Common\Models\BeautyParlor;
use PhalconPlus\Api\Common\ResultStatus;

class ServiceList extends BaseMethod
{
    public function run(){
        
        $id = intval($this->getDataItem('id',0));
        $page = intval($this->getDataItem('page',1));
        $limit = $this->getConfig()->limit;
        $offset = ($page-1)*$limit;
        if(0 < $id) {
            $service = BeautyParlorService::query()
                ->columns([
                'service_id id',
                'service_cover cover',
                'service_name name',
                'service_price price',
                'service_unit unit',
                'service_description description'])
                ->where('service_state>0 and service_is_sell = 1 and beauty_parlor_id=:bid:')
                ->bind(['bid'=>$id])
                ->limit($limit,$offset)
                ->execute()->toArray();
        } else {
            return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '参数异常');
        }
        $services = [];
        if ($service) {
            foreach($service as $d) {
                $d['cover'] = PicUrl::BeautyParlorCover($d['cover'], $this->getDi());
                $unit = $d['unit'];
                unset($d['unit']);
                $d['price_show'] = '';
                if($d['price'] > 0) {
                    $d['price_show'] = $d['price'] . '元' . ($unit ? '/' . $unit : '');
                }
                $services[] = $d;
            }
            $this->setResult($services);   
        }else{
            $this->setResult($services);
        }
    }
}